#!/opt/lampp/bin/perl -w
use strict;
use warnings;
use DBI;
require('function.pl');

my $db_host = 'localhost';
my $db = 'crm';
my $db_user = 'zjxia';
my $db_password = 'bblovebb';
my $db_conn = DBI->connect("DBI:mysql:database=$db;host=$db_host", $db_user, $db_password);
$db_conn->do('set names gb2312');

my $date_str = get_date_str(-1);
open OUT, ">report/$date_str";
my $sum = execute_scalar('select count(*) from snapshot', $db_conn);
print OUT "数据量：$sum\n今日入库量：\n";
my $sql = "select domain, count(domain) from snapshot where update_time between '$date_str' and '$date_str 23:59:59' group by domain";
$db_conn->prepare($sql);
my $request = $db_conn->prepare($sql);
$request->execute();
while (my ($domain, $sum) = $request->fetchrow_array) {
	print OUT "$domain\t$sum\n";
}
close OUT;
